package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WebUserCardTimeLog;
import com.ruoyi.system.service.IWebUserCardTimeLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 次卡消费记录Controller
 * 
 * @author wsliupan@126.com
 * @date 2021-06-27
 */
@Controller
@RequestMapping("/system/UserCardTimeLog")
public class WebUserCardTimeLogController extends BaseController
{
    private String prefix = "system/UserCardTimeLog";

    @Autowired
    private IWebUserCardTimeLogService webUserCardTimeLogService;

    @RequiresPermissions("system:UserCardTimeLog:view")
    @GetMapping()
    public String UserCardTimeLog()
    {
        return prefix + "/UserCardTimeLog";
    }

    /**
     * 查询次卡消费记录列表
     */
    @RequiresPermissions("system:UserCardTimeLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebUserCardTimeLog webUserCardTimeLog)
    {
        startPage();
        List<WebUserCardTimeLog> list = webUserCardTimeLogService.selectWebUserCardTimeLogList(webUserCardTimeLog);
        return getDataTable(list);
    }

    /**
     * 导出次卡消费记录列表
     */
    @RequiresPermissions("system:UserCardTimeLog:export")
    @Log(title = "次卡消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebUserCardTimeLog webUserCardTimeLog)
    {
        List<WebUserCardTimeLog> list = webUserCardTimeLogService.selectWebUserCardTimeLogList(webUserCardTimeLog);
        ExcelUtil<WebUserCardTimeLog> util = new ExcelUtil<WebUserCardTimeLog>(WebUserCardTimeLog.class);
        return util.exportExcel(list, "次卡消费记录数据");
    }

    /**
     * 新增次卡消费记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存次卡消费记录
     */
    @RequiresPermissions("system:UserCardTimeLog:add")
    @Log(title = "次卡消费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebUserCardTimeLog webUserCardTimeLog)
    {
        return toAjax(webUserCardTimeLogService.insertWebUserCardTimeLog(webUserCardTimeLog));
    }

    /**
     * 修改次卡消费记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebUserCardTimeLog webUserCardTimeLog = null;
        if(id == null || id ==  -1){
            webUserCardTimeLog = new WebUserCardTimeLog();
        }else{
            webUserCardTimeLog = webUserCardTimeLogService.getById(id);
        }
        mmap.put("webUserCardTimeLog", webUserCardTimeLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存次卡消费记录
     */
    @RequiresPermissions("system:UserCardTimeLog:edit")
    @Log(title = "次卡消费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebUserCardTimeLog webUserCardTimeLog)
    {
        return toAjax(webUserCardTimeLogService.updateWebUserCardTimeLog(webUserCardTimeLog));
    }

    /**
     * 删除次卡消费记录
     */
    @RequiresPermissions("system:UserCardTimeLog:remove")
    @Log(title = "次卡消费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webUserCardTimeLogService.deleteWebUserCardTimeLogByIds(ids));
    }
}
